<template>
  <div>
    <el-button type='primary' @click='start'>start</el-button>
    <div id='chart'></div>
  </div>
</template>

<script>
export default {
  name: 'chart',
  methods: {
    start() {
      let chart = this.$echarts.init(document.getElementById('chart'))

      let  option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        series: [
          {
            name: 'Direct',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [0,1,3,2,1,4,2]
          },
          {
            name: 'Mail Ad',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [1,1,2,2,1,3,1]
          },
          {
            name: 'Affiliate Ad',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [ 3,2,1,1,2,3,4]
          },
          {
            name: 'Video Ad',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [1,2,3,3,2,1,2]
          },
          {
            name: 'Search Engine',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [3,0,1,2,2,2,3]
          }
        ]
      };
      chart.setOption(option)
    }
  }
}
</script>

<style scoped>

.el-button {
  margin-bottom: 20px;
}

#chart {
  width: 100%;
  height: 500px;
  margin: 0 auto;
}
</style>